<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>02天气案例-监视属性</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="demo">
            <h1>今天天气{{info}}</h1>
            <button @click = "query">查询天气</button><br>
            <img :src="url">
            <button>监视属性</button>
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        new Vue({
            el:'#demo',
            data:{
                isHot:true,
                url:'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
            },
            methods:{
                query(){
                    this.isHot  = !this.isHot;
                }
            },
            computed:{
                info(){
                    return this.isHot?'炎热':'凉爽';     
                }
            },
            watch:{
                isHot:{
                    handler(newValue,oldValue){
                        console.log('监听到数据' + newValue + oldValue);
                        if (newValue) this.url = 'https://s3.ax1x.com/2020/12/13/reC1IA.jpg'
                        else this.url = 'https://s3.ax1x.com/2020/12/13/reCaqg.jpg' 
                    }
                }
            }
        })
    </script>
</html>